<script type="text/javascript">
    var bardata = <?php echo json_encode($g_data['data']['y-axis']);?>;
    var x_axis = <?php echo json_encode($g_data['data']['x-axis']);?>;
    var graph_title = <?php echo json_encode($graph_title);?>;
</script>
<div class="container">

    <?php echo $this->element('page_header'); ?>

    <div class="row">
        <div class="span3">
            <?php echo $this->element('reports/navigation'); ?>

            <div id="page-title" class="clearfix">
                <h1 style="font-size: 16px;"><?php echo 'Report Filter Parameters';?></h1>
                <?php echo $this->Form->create('Query', array('id' => 'form-query', 'inputDefaults' => array('label' => false,'div' => false)));?>
                <ul class="breadcrumb">
                    <li>
                        <span><?php echo 'Start Date:'; ?></span>
                        <?php echo $this->Form->input('start_dt', array('id'=>'start_dt', 'class' => 'span2 date-masking validate[required]','default'=>$start_dt,'placeholder'=>'yyyy-mm-dd', 'div' => false, 'label' => false,)); ?>
                        <span class="divider"></span>
                    </li>
                    <li>
                        <span><?php echo 'End Date:'; ?></span>
                        <?php echo $this->Form->input('end_dt', array('id'=>'end_dt', 'class' => 'span2 date-masking validate[required]','default'=>$end_dt,'placeholder'=>'yyyy-mm-dd', 'div' => false, 'label' => false,)); ?>
                        <span class="divider"></span>
                    </li>
                    <li>
                        <span><?php echo 'Assign To:'; ?></span>
                        <?php echo $this->Form->input('user', array('id'=>'user', 'class' => '','default'=>$default_user,'options'=>$user_list, 'div' => false, 'label' => false,)); ?>
                        <span class="divider"></span>
                    </li>
                    <li>
                        <span><?php echo 'Priority:'; ?></span>
                        <?php echo $this->Form->input('priority', array('id'=>'priority', 'class' => '','default'=>$default_priority,'options'=>$priorities, 'div' => false, 'label' => false,)); ?>
                        <span class="divider"></span>
                    </li>
                    <li>
                        <span><?php echo 'Project:'; ?></span>
                        <?php echo $this->Form->input('project', array('id'=>'project', 'class' => '','default'=>$default_project,'options'=>$projects, 'div' => false, 'label' => false,)); ?>
                        <span class="divider"></span>
                    </li>
                    <li>
                        <span><?php echo 'Department:'; ?></span>
                        <?php echo $this->Form->input('department', array('id'=>'department', 'class' => '','default'=>$default_department,'options'=>$departments, 'div' => false, 'label' => false,)); ?>
                        <span class="divider"></span>
                    </li>
                    <li>
                        <span><?php echo 'Branch:'; ?></span>
                        <?php echo $this->Form->input('branch', array('id'=>'branch', 'class' => '','default'=>$default_branch,'options'=>$branches, 'div' => false, 'label' => false,)); ?>
                        <span class="divider"></span>
                    </li>
                    <li>
                        <button class="btn btn-large btn-primary" type="submit" id="query-btn">Re-Query </button>
                        <?php echo $this->Form->input('user_name', array('type'=>'hidden','id'=>'user_name', 'value'=>'' )); ?>
                        <?php echo $this->Form->input('priority_name', array('type'=>'hidden','id'=>'priority_name', 'value'=>'' )); ?>
                        <?php echo $this->Form->input('project_name', array('type'=>'hidden','id'=>'project_name', 'value'=>'' )); ?>
                        <?php echo $this->Form->input('department_name', array('type'=>'hidden','id'=>'department_name', 'value'=>'' )); ?>
                        <?php echo $this->Form->input('branch_name', array('type'=>'hidden','id'=>'branch_name', 'value'=>'' )); ?>
                        <span class="divider"></span>
                    </li>

                </ul>
                <?php echo $this->Form->end();?>
            </div>
        </div>
        <div class="span9">

            <div class="widget">

                <div class="widget-header">
                    <h3>
                        <i class="icon-th-list"></i>
                        Report Chart
                    </h3>
                </div> <!-- /widget-header -->

                <div class="widget-content">
                    <div id="bar-content"></div>

                    <script type="text/javascript">
                        $(function () {
                            $(document).ready(function() {
                                var options_bar = {
                                    /* exporting:{
                                     url:'http://localhost/exporting-server/'
                                     },*/
                                    chart: {
                                        renderTo: 'bar-content',
                                        type: 'column'
                                    },
                                    title: {
                                        text: graph_title
                                    },
                                    xAxis: {
                                        categories: x_axis
                                    },
                                    yAxis: {
                                        min: 0,
                                        title: {
                                            text: 'Count'
                                        },
                                        stackLabels: {
                                            enabled: true,
                                            style: {
                                                fontWeight: 'bold',
                                                color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
                                            }
                                        }
                                    },
                                    tooltip: {
                                        formatter: function(series) {
                                            return ''+this.series.name +': '+ this.y;
                                        }
                                    },
                                    plotOptions: {
                                        column: {
                                            stacking: 'normal',
                                            dataLabels: {
                                                enabled: true,
                                                color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
                                            },
                                            pointPadding: 0.2,
                                            borderWidth: 0
                                        }
                                    },
                                    series: bardata
                                };
                                var chart_bar = new Highcharts.Chart(options_bar);
                            });
                        });
                    </script>
                </div> <!-- /widget-content -->

            </div> <!-- /widget -->

            <div class="row">
                <div class="span9">
                    <div class="widget">
                        <div class="widget-header">
                            <h3>
                                <i class="icon-th-list"></i>
                                <?php echo $table_title ?>
                            </h3>
                            <div class="widget-actions">
                                <button type="button" id="print-btn" class="btn btn-small btn-primary">Print</button>
                                <button type="button" id="export-btn" class="btn btn-small btn-secondary">Export</button>
                            </div>
                        </div> <!-- /widget-header -->

                        <div class="widget-content">
                            <table class="table table-bordered table-striped table-highlight">
                                <thead>
                                    <tr>
                                        <?php
                                        foreach($g_data['table']['thead'] as $h){
                                            ?>
                                            <th><?php echo $h ;?></th>
                                        <?php
                                        }
                                        ?>
                                    </tr>
                                </thead>
                                <tbody>
                                <?php
                                foreach($g_data['table']['tbody'] as $tbd_arr){
                                    ?>
                                    <tr>
                                        <?php
                                        foreach($tbd_arr as $key => $v){
                                            ?>
                                            <td><?php echo $v ;?></td>
                                        <?php
                                        }
                                        ?>
                                    </tr>
                                <?php
                                }
                                ?>
                                </tbody>
                            </table>
                        </div> <!-- /widget-content -->
                    </div> <!-- /widget -->

                </div>
            </div>
        </div>

    </div> <!-- /.row -->


    <form id="print-export-form" method="post" action="<?php echo $this->Html->url(array('controller' => 'Reports', 'action' => 'print_export_consolidated')); ?>" target="PrintExportWindow">
        <input type="hidden" name="data_type" id="data_type" value="" />
        <input type="hidden" name="data_start_dt" id="data_start_dt"  value="" />
        <input type="hidden" name="data_end_dt" id="data_end_dt"  value="" />
        <input type="hidden" name="data_user" id="data_user"  value="" />
        <input type="hidden" name="data_user_name" id="data_user_name"  value="" />
        <input type="hidden" name="data_priority" id="data_priority"  value="" />
        <input type="hidden" name="data_priority_name" id="data_priority_name"  value="" />
        <input type="hidden" name="data_project" id="data_project"  value="" />
        <input type="hidden" name="data_project_name" id="data_project_name"  value="" />
        <input type="hidden" name="data_department" id="data_department"  value="" />
        <input type="hidden" name="data_department_name" id="data_department_name"  value="" />
        <input type="hidden" name="data_branch" id="data_branch"  value="" />
        <input type="hidden" name="data_branch_name" id="data_branch_name"  value="" />
    </form>
</div> <!-- /.container -->

<!-- URLs -->
<input type="hidden" id="table-url" value="<?php echo $this->Html->url(array('controller' => 'Tickets', 'action' => 'index/get')); ?>" />
<input type="hidden" id="table-editable-url" value="<?php echo $this->Html->url(array('controller' => 'Tickets', 'action' => 'index/save')); ?>" />
<input type="hidden" id="table_delete_url" value="<?php echo $this->Html->url(array('controller' => 'Tickets', 'action' => 'index/delete')); ?>" />
<input type="hidden" id="update_ticket_url" value="<?php echo $this->Html->url(array('controller' => 'Tickets', 'action' => 'update_ticket')); ?>" />
<input type="hidden" id="track_ticket_url" value="<?php echo $this->Html->url(array('controller' => 'Tickets', 'action' => 'track_ticket')); ?>" />
<input type="hidden" id="track_ticket_url" value="<?php echo $this->Html->url(array('controller' => 'Tickets', 'action' => 'track_ticket')); ?>" />


<?php
    echo $this->Html->script('Scripts/report_consolidated.js');
    echo $this->Html->script('plugins/highcharts/exporting.js');
?>